{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{% load mytags %}

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>批量执行命令状态</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">Config option 1</a>
                            </li>
                            <li><a href="#">Config option 2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <div id="txtHint">
                        <form action="" >
                            <table class="table table-hover table-bordered">
                                <thead>
                                    <th class="text-center">项目</th>
                                    <th class="text-center">目标IP</th>
                                    <th class="text-center">命令</th>
                                    <th class="text-center">状态</th>
                                    <th class="text-center">日志信息</th>
                                    <th class="text-center">返回结果</th>
{#                                    <th class="text-center">开始时间</th>#}
{#                                    <th class="text-center">结束时间</th>#}
                                    <th class="text-center">执行时间</th>
                                    <th class="text-center">操作人</th>
                                </thead>
                                <tbody>
                                    {% for num in status_info %}
                                    <tr class="text-center">
                                        <td>{{num.project}}</td>
                                        <td>{{num.p_ip}}</td>
                                        <td>{{num.cmd}}</td>
                                        <td>
                                            <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: {{num.status}}">{{num.status}}</div>
                                        </td>
                                        <td>{{num.log|safe}}</td>
                                        <td><a data-toggle="modal" data-target="#display_result_{{num.id}}" onclick="timer=window.clearInterval(timer)">查看结果</a></td>
{#                                        <td>{{num.start_time| print_time }}</td>#}
{#                                        {% ifequal num.end_time None %}#}
{#                                            <td>执行中</td>#}
{#                                        {% else %}#}
{#                                            <td>{{num.end_time| print_time }}</td>#}
{#                                        {% endifequal %}#}
                                        <td>{{ num.total_time }}s</td>
                                        <td>{{num.operator}}</td>
                                    </tr>
                                    <tr>
                                        <td colspan="8">
                                            {% if num.result == "None" %}
                                                <pre>执行中,请稍候...</pre>
                                            {% else %}
                                                <pre>{{ num.result }}</pre>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    <div class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" id="display_result_{{num.id}}">
                                      <div class="modal-dialog modal-lg" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title" id="gridSystemModalLabel" align="center">{{ num.p_ip }} 执行 {{ num.cmd }} 返回结果详细信息</h4>
                                          </div>
                                          <div class="modal-body">
                                            <div class="container-fluid" align="pull-left">
                                                <pre style="color:green;">{{ num.result|get_data_log }}</pre>
                                                <pre style="color:red;">{{ num.result|get_error_log }}</pre>
                                            </div>
                                          </div>
                                        </div><!-- /.modal-content -->
                                      </div><!-- /.modal-dialog -->
                                    </div><!-- /.modal -->

                                    {% endfor %}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
        {
        xmlhttp=new XMLHttpRequest();
        }
else
        {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                }
        }
xmlhttp.open("GET","{% url 'exec_cmds_status' %}?start_time={{start_time}}",true);
xmlhttp.send()
}
</script>
<br>
<br>
<SCRIPT LANGUAGE="JavaScript">
    function CountDown()
    {
            loadXMLDoc();
            //document.getElementById("demo").innerHTML=loadXMLDoc();
            // console.log(document.getElementById("txtHint").innerHTML);

    }
    timer = setInterval("CountDown()",2000);
</SCRIPT>


{%endblock%}